package com.admin.system.modules.system.rest;

import com.admin.core.dto.EmailDTO;
import com.admin.core.dto.cache.EmailParamConfigBO;
import com.admin.core.dto.cache.ParamConfigCacheBO;
import com.admin.logging.annotation.Log;
import com.admin.system.util.EmailUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * 发送邮件
 *
 * @author sq-lan
 */
@RestController
@RequestMapping("api/email")
@Api(tags = "工具：邮件管理")
public class EmailController {


    @GetMapping
    public ResponseEntity<EmailParamConfigBO> emailConfig() {
        return new ResponseEntity<>(ParamConfigCacheBO.emailParamConfig, HttpStatus.OK);
    }

    @Log(description = "配置邮件")
    @PutMapping
    @ApiOperation("配置邮件")
    public ResponseEntity<Object> modify(@Validated @RequestBody EmailParamConfigBO emailConfig) throws Exception {

        return new ResponseEntity<>(HttpStatus.OK);
    }

    @Log(description = "发送邮件")
    @PostMapping
    @ApiOperation("发送邮件")
    public ResponseEntity<Object> send(@Validated @RequestBody EmailDTO dto) {
        EmailUtil.send(dto, ParamConfigCacheBO.emailParamConfig);
        return new ResponseEntity<>(HttpStatus.OK);
    }
}
